﻿using RealtReview.DataAccess.Entities;
using RealtyReview.Business.Helpers;
using RealtyReview.Business.Models.ViewModels;

namespace RealtyReview.Business.Mappings
{
    public static partial class EntityMap
    {
        public static Review ToReview(this ReviewViewModel model)
        {
            var json = Serializer.ToJson(model);
            return new Review
            {
                ArrivialDate = model.ArrivialDate,
                EvictionDate = model.EvictionDate,
                Price = model.Price,
                RentType = model.RentType,
                OptionalParameters = json,
                Status = model.Status
            };
        }

        public static ReviewViewModel ToReviewViewModel(this Review entity)
        {
            var json = Serializer.ToObject<ReviewViewModel>(entity.OptionalParameters);
            return new ReviewViewModel
            {
                ArrivialDate = entity.ArrivialDate,
                AvailiableTransportModes =  (json !=null) ? json.AvailiableTransportModes : null,
                Description =  (json !=null) ? json.Description : null,
                EvictionDate = entity.EvictionDate,
                InternetQuality =  (json !=null) ? json.InternetQuality : null,
                NeighborsNature =  (json !=null) ? json.NeighborsNature : null,
                Price = entity.Price,
                RentType = entity.RentType,
                RepairQuality =  (json !=null) ? json.RepairQuality : null,
                WcType = (json != null) ? json.WcType : null,
            };
        }
    }
}
